<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jqueryForm/jquery.form.js"></script>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="releaseList"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">注册用户管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
            </form>


            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>状态</th>
                    <th></th>
                </tr>



            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.title!}</td>
                       <td><img src="${entity.coverUrl!}" width="30px"> </td>
                       <td>${(entity.place.id)!}</td>
                       <td>${entity.author.nickName}</td>
                       <td>${entity.stateName!}</td>
                        <td>
                            <button class="stateBtn" data-tid="${entity.id}" data-state="-1">取消发布</button>
                            <button class="showTravel"  data-tid="${entity.id}">查看文章</button>
                            <button class="commendBtn" data-json='${entity.json}'>推荐</button>
                        </td>

                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="traveModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">文章内容</h4>
            </div>
            <div class="modal-body" id="modalBody">

            </div>
            <div class="modal-footer">

            </div>
        </div>
    </div>

</div>

<div class="modal fade" id="strategyModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="travel.id">
                    <input type="hidden"  name="user.id">
                    <input type="hidden"  name="state" value="4">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >封面：</label>
                        <div class="col-sm-6">
                            <img  id="coverImg"  width="100%" >
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" readonly onclick="WdatePicker();" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>

                </form>
                <form id="fileForm" action="/images/xx.do" method="post" enctype="multipart/form-data"/>
                    <input id="fileBtn" type="file" class="form-control" name="file" style="display: none" accept="image/*">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>
<style>
    #traveModal img{
        width: 100%;
    }

</style>

<script>
    //发布拒绝按钮
    $(".stateBtn").click(function () {
        var id =$(this).data("tid");
        var state =$(this).data("state");
        $.get("/travel/updateState.do",{id:id,state:state},function (data) {
            if (data.success) {
                reload();
            }else{
                $.messager.alert(data.msg);
            }
        })
    })
    //查看文章
    $(".showTravel").click(function () {
        var id =$(this).data("tid");
        $.get("/travel/selectContentByTravelId.do",{id:id},function (data) {
            console.log(data.content);
            $("#modalBody").html(data.content);
            console.log($("#modalBody"));

            $("#traveModal").modal("show")
        })
    })

    //推荐
    $(".commendBtn").click(function () {
       var json=$(this).data("json");
        $("#editForm input[name='travel.id']").val(json.id);
        $("#editForm input[name='user.id']").val(json.author.id);
        console.log(json.author.id);
        console.log("==============================");
        $("#editForm input[name='title']").val(json.title);
        $("#coverImg").prop("src",json.coverUrl);
        $("#strategyModal").modal("show")
        console.log(json.coverUrl);
    })

    //点击图片
    $("#coverImg").click(function () {
        $("#fileBtn").click();
    })


    //文件按钮改变事件
    $("#fileBtn").change(function () {
        if ($(this).val()) {
            $("#fileForm").ajaxSubmit(function (data) {
                if (data.url) {
                    $("#coverImg").prop("src",data.url)
                }
            })
        }
    })

    //保存
    $(".submitBtn").click(function () {
        var src= $("#coverImg").attr("src");
        $("#editForm input[name='coverUrl']").val(src);
        console.log(src);
        $("#editForm").ajaxSubmit(function (data) {
            if (data.success) {
                reload();
            }

        })
    })
</script>

</body>
</html>